$(function(){
	$.post(basePath+"/facility/getEtopFacilityList2.do?facilityType=0",{},function(data){
		
		 if(data.status==10001){
			 for(var i=0;i<data.data.length;i++){
				 $("#room").append('<option value="'+data.data[i].id+'">'+data.data[i].facilityName+'</option>')
			 }
			 
		 }else{
			   swal( data.msg, "","error");
		 }
		 
	});
});

function getInfo(){
	
	var facilityId=$("#room").val();
	$.post(basePath+"/serviceFacility/getServiceList2.do?facilityId="+facilityId,{},function(data){
		
		 if(data.status==10001){
			 var arrays=[];
			 for(var i=0;i<data.data.length;i++){
				 var one={
						 title: "会议室预约",
						 start: getData(data.data[i].beginTime),
						 end: getData(data.data[i].endTime)
				 }
				 
				 arrays.push(one)
			 }
			 $('#calendar').fullCalendar('destroy');
			 $("#calendar").fullCalendar({
					header: {
						left: "prev,next",
						center: "title",
						right: ""
					},
					events: arrays
			})
			 
		 }else{
			   swal( data.msg, "","error");
		 }
		 
	});	
	
}



function getData(timestamp){
	var date = new Date(timestamp);
	Y = date.getFullYear();
	M = date.getMonth();
	D = date.getDate();
	//(date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)
	return new Date(Y, M, D);
}


function appoint(){
	if($("#start").val()=="" || $("#end").val()==""){
		alert("时间未选择");
		return;
	}
	var param={
			"beginTimestamp":$("#start").val(),
			"endTimestamp":$("#end").val(),
			"facilityId":$("#room").val()
	};
	$.post(basePath+"/serviceFacility/add.do",param,function(data){
		
		 if(data.status==10001){
			 alert("预约成功");
			 getInfo();
		 }else{
			 alert("预约失败");
		 }
		 
	});
	
}
